home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1988 / 07 / bench / benchnew.bas next >
BASIC Source File  |  1988-04-29  |  3KB  |  130 lines

  1. [FILENAME: BENCHNEW.BAS]
  2.  
  3. DEFLNG A-Z
  4. DIM t!(28)
  5. OPEN "bas6new.tim" FOR OUTPUT AS #1
  6. DIM x1 AS STRING * 1
  7. DIM x26 AS STRING * 26
  8. DIM x70 AS STRING * 70
  9. DIM x10000 AS STRING * 10000
  10.  
  11. 'time for a raw long integer loop, executed 1,000,000 times.
  12. t! = TIMER
  13. FOR i = 1 TO 1000
  14.   FOR j = 1 TO 1000
  15.   NEXT j
  16. NEXT i
  17. t!(0) = TIMER - t!
  18.  
  19. 'time for 1,000,000 long integer assignments.
  20. y = 5&: z = -5&
  21. t! = TIMER
  22. FOR i = 1 TO 1000
  23.   FOR j = 1 TO 1000
  24.   x = y
  25.   x = z
  26.   NEXT j
  27. NEXT i
  28. t!(1) = (TIMER - t! - t!(0)) / 2
  29.  
  30. 'time for 1,000,000 long integer adds
  31. t! = TIMER
  32. FOR i = 1 TO 1000
  33.   FOR j = 1 TO 1000
  34.   x = x + y
  35.   NEXT j
  36. NEXT i
  37. t!(2) = TIMER - t! - t!(1)
  38.  
  39. 'time for 1,000,000 long integer subtracts
  40. x = 0
  41. t! = TIMER
  42. FOR i = 1 TO 1000
  43.   FOR j = 1 TO 1000
  44.   x = x - y
  45.   NEXT j
  46. NEXT i
  47. t!(3) = TIMER - t! - t!(1)
  48.  
  49. 'time for 1,000,000 long integer multiplies
  50. t! = TIMER
  51. FOR i = 1 TO 1000
  52.   FOR j = 1 TO 1000
  53.   x = i * j
  54.   NEXT j
  55. NEXT i
  56. t!(4) = TIMER - t! - t!(1)
  57.  
  58. 'time for 1,000,000 long integer divides
  59. t! = TIMER
  60. FOR i = 1 TO 1000
  61.   FOR j = 1 TO 1000
  62.   x = i \ j
  63.   NEXT j
  64. NEXT i
  65. t!(5) = TIMER - t! - t!(1)
  66.  
  67. 'time for 100,000 fixed string assignments
  68. t! = TIMER
  69. FOR i = 1 TO 1000
  70.   FOR j = 1 TO 100
  71.   x26 = "abcdefghijklmnopqrstuvwxyz"
  72.   x26 = "zyxwvutrsqponmlkjihgfedcba"
  73.   NEXT j
  74. NEXT i
  75. t!(6) = (TIMER - t! - t!(0) / 10) / 2
  76.  
  77. 'time for 100,000 fixed string MID$ operations
  78. k = 17
  79. t! = TIMER
  80. FOR i = 1 TO 1000
  81.   FOR j = 1 TO 100
  82.   MID$(x26, k, 1) = "d"
  83.   NEXT j
  84. NEXT i
  85. t!(7) = TIMER - t! - t!(0) / 10
  86.  
  87. 'time for 10,000 fixed string "concatenations"
  88. x$ = ""
  89. t! = TIMER
  90. FOR i = 1 TO 10000
  91.   MID$(x10000, i, 1) = "a"
  92. NEXT i
  93. t!(8) = TIMER - t! - t!(0) / 100
  94.  
  95. 'following are logical comparisons and operators
  96.  
  97. 'time for 1,000,000 long integer comparisons
  98. x = 5&: y = -5&
  99. t! = TIMER
  100. FOR i = 1 TO 1000
  101.   FOR j = 1 TO 1000
  102.     IF i < y THEN x = 1
  103.   NEXT j
  104. NEXT i
  105. t!(23) = TIMER - t! - t!(0)
  106.  
  107. 'screen output: print 1,000 70-byte fixed strings
  108. x70 = STRING$(70, 66)
  109. t! = TIMER
  110. FOR i = 1 TO 1000
  111.   PRINT x70
  112. NEXT i
  113. t!(28) = TIMER - t! - t!(0) / 1000
  114.  
  115.  
  116. 'print results of benchmark
  117. PRINT #1, "Raw long integer loop, 1,000,000 iterations:"; TAB(45); t!(0)
  118. PRINT #1, "1,000,000 long integer assignments:"; TAB(45); t!(1)
  119. PRINT #1, "1,000,000 long integer additions:"; TAB(45); t!(2)
  120. PRINT #1, "1,000,000 long integer subtractions:"; TAB(45); t!(3)
  121. PRINT #1, "1,000,000 long integer multiplications:"; TAB(45); t!(4)
  122. PRINT #1, "1,000,000 long integer divisions:"; TAB(45); t!(5)
  123. PRINT #1, "100,000 fixed string assignments:"; TAB(45); t!(6)
  124. PRINT #1, "100,000 fixed string MID$ operations:"; TAB(45); t!(7)
  125. PRINT #1, "10,000 fixed string concatenations:"; TAB(45); t!(8)
  126. PRINT #1, "1,000,000 long integer comparisons:"; TAB(45); t!(23)
  127. PRINT #1, "Print 1,000 70-byte strings to the screen:"; TAB(45); t!(28)
  128. END
  129.  
  130.